<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="lib/layui/css/layui.css">
    <script src="lib/layui/layui.js"></script>
    <script src="lib/jquery-1.12.4.js"></script>

</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>
<span style="float: right; color: red; font-size: 20px;margin: 10px 20px" id="span"></span>
</body>
<script>
    var replenishmentId = decodeURI(window.location.href).split("?replenishmentId=")[1];
    //console.log(replenishmentId);
    layui.use(['table','form','laydate','element'], function () {
        var table = layui.table,
            form = layui.form,
            element = layui.element,
            laydate = layui.laydate;

        table.render({
            elem: '#test',
            url: 'xp/complete/getOne',
            where: {
                replenishmentId : replenishmentId
            },
            //toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            id: 'orderInfo',
            // defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            //     title: '提示',
            //     layEvent: 'LAYTABLE_TIPS',
            //     icon: 'layui-icon-tips'
            // }],
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": 10, //解析数据长度
                    "data": res.obj //解析数据列表
                };
            },
            cols: [
                [
                    {
                        field: 'goodsId',
                        title: '商品编号',
                        align: 'center'
                    }, {
                        field: 'goodsName',
                        title: '商品名称',
                        align: 'center'
                    }, {
                        field: 'specificationName',
                        title: '规格',
                        align: 'center'
                    }, {
                        field: 'quantityOfGoods',
                        title: '补货数量',
                        align: 'center',
                        width: 100,
                        templet: function (d) {
                            return Number(d.quantityOfGoods).toFixed(2);
                        }
                    }, {
                        field: 'purchasePrice',
                        title: '采购价',
                        align: 'center',
                        templet: function (d) {
                            return Number(d.purchasePrice).toFixed(2);
                        }
                    }
                ]
            ],
            page: true,
            done: function () {
                count();
            }
        });

    });
    function count() {
        var quantityLength = $("[data-field='quantityOfGoods']").length;
        var quantity = $("[data-field='quantityOfGoods']").find('div').text();
        var price = $("[data-field='purchasePrice']").find('div').text();
        var result1 = [];
        var result2 = [];
        for(var i=0; i< quantityLength-1; i++){
            result1.push(Number($("[data-field='quantityOfGoods']").eq(i+1).find('div').text()));
            result2.push(Number($("[data-field='purchasePrice']").eq(i+1).find('div').text()));
        }
        var total = 0.0000;
        for(var j=0; j<result1.length; j++){
            total += result1[j]*result2[j];
        }
        console.log(result1);
        console.log(result2);
        $("#span").html('￥'+total);
    }

</script>
</html>